Add test for Esplora client on Regtest #967
Add test for Esplora client on Regtest #967thunderbiscuit merged 2 commits intobitcoindevkit:masterfrom
Conversation
| regtestEnv.mine(2) | ||
|
|
||
| //Wait 8 second for mining to complete and for esplora to index the new blocks before scanning | ||
| delay(8.seconds) |
There was a problem hiding this comment.
has 8 seconds proven to always be enough time for this?
There was a problem hiding this comment.
Yes the 8 second delay is really not a clean way to do this (what if the CI is much slower than local, or the opposite? One side or another you're waiting for longer than you should and it's just overall hacky).
We used this approach to get something working and opened an issue on regtest-toolbox thinking maybe a solution could be added there, but I think @ItoroD's idea of polling the Electrum server until it sees the transaction or block is probably the best way to do this test-side.
I'll add the polling loop here and test locally between runs to see the general feel for it (maybe looping on 1/10th of a second is too much? Maybe not). But in any case I'll use that approach here, and we should clean up the JVM tests as well.
There was a problem hiding this comment.
yeah the polling loop sounds cleaner, I like it
There was a problem hiding this comment.
I ended up with this:
// Wait for the Esplora client to see the transaction. Try 5x per second for 20 seconds.
repeat(100) {
if (esploraClient.getTx(txid) != null) return@repeat
delay(200.milliseconds)
}Which usually takes between 10 and 30 loops to complete on my machine.
There was a problem hiding this comment.
return@runBlocking breaks out of the loop.
There was a problem hiding this comment.
return@runBlocking is nice but I think it would exit the whole test body here not just the polling loop?
There was a problem hiding this comment.
There was a problem hiding this comment.
Good catch @reez. I updated with:
for (i in 0..99) {
if (esploraClient.getTx(txid) != null) break
delay(200.milliseconds)
}which accomplishes the stated goal of only running the required number of iterations.
9ad254e to
2c7c7f6
Compare
231293a to
0b8fafc
Compare
|
Ready for final review. |
0b8fafc to
efab89b
Compare
This PR brings in the regtest-toolbox library as a test dependency (not shipped with the release artifacts) in order to control a local regtest node and allow for testing clients in our CI workflows. It also brings in the Regtest Infinity Pro as a service that gets fired up before the CI runs the tests.
We are currently using this setup in bdk-jvm with success.
Using this would allow us to test clients, and better see/verify changes in the API on client PRs (for example in #965).
Notes to the reviewers
Opened as a discussion piece.
Documentation
It does not affect the public API.
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features: